package com.example.demo.common;

import com.example.demo.model.ArticleInfo;
import com.example.demo.model.UserInfo;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

import static com.example.demo.common.Constant.USER_SESSION_KEY;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-02-03
 * Time: 23:33
 */
public class LoginSession {

    public  static UserInfo getSessionUserInfo(HttpServletRequest request) {
        //得到session
        HttpSession session = request.getSession(false);
        //判断session以及用户登录状态是否存在
        if(session!=null && session.getAttribute(USER_SESSION_KEY)!=null) {
            //得到用户信息,返回
           return (UserInfo) session.getAttribute(USER_SESSION_KEY);
        }
        return null;
    }
}
